<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 路帅
  Date: 2021/8/2
  Time: 10:47
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<script>
    function deleteBy(id) {
        if (confirm("确定删除吗？")) {
            window.location.href = "/show?cmd=delete&id=" + id;
        }
    }

    window.onload = function () {
        var trc = document.getElementsByClassName("trs");
        for (var i = 0; i < trc.length; i++) {
            trc[i].onmouseover = function () {
                this.style.backgroundColor = "#0ef649";
            }
            trc[i].onmouseout = function () {
                this.style.backgroundColor = "";
            }
        }
    }

    function goPage(pageNum) {
        document.getElementById("currentPage").value = pageNum;
        //找到页面表单，提交 -- document.forms获取当前页面中的所有表单
        document.forms[0].submit();
    }

    function changePage() {
        document.forms[0].submit();
    }
</script>
<style type="text/css">
    tr {
        line-height: 2em;
        text-align: center;
        color: #f66f6f;
    }

    input {
        text-align: center;
    }

    a {
        text-decoration: none;
    }

    #up {
        position: fixed;
        top: 0;
        right: 10px;
        word-spacing: 1em;
    }
</style>
<body>
<%
    Object user = session.getAttribute("USER_IN_SESSION");
    if(user==null){
        response.sendRedirect("login.jsp");
    }
%>
<h3>欢迎，${USER_IN_SESSION.username}
    <img align="left" src="${USER_IN_SESSION.headImg}" title="更换头像" width="100px">
</h3>
<div id="up">
    <a href="/change">修改用户信息</a>
    <a href="/logout">退出</a>
</div>
<br/>
<br/>
<br/>
<form action="#" method="post">
    <div width="80%" align="center">
        产品名：<input type="text" name="productName" value="${qo.productName}">
        价格：<input type="text" name="minSalePrice" value="${qo.minSalePrice}">
        - <input type="text" name="maxSalePrice" value="${qo.maxSalePrice}">
        <input type="submit" value="查询">
    </div>
    <table border="1" cellpadding="10px" cellspacing="0" width="80%" align="center">
        <tr>
            <th>编号</th>
            <th>商品名</th>
            <th>分类编号</th>
            <th>零售价</th>
            <th>供应商</th>
            <th>品牌</th>
            <th>折扣</th>
            <th>进货价</th>
            <th>操作</th>
        </tr>
        <c:forEach var="p" items="${pageResult.data}" varStatus="status">
            <tr class="trs">
                <td>${p.id}</td>
                <td>${p.productName}</td>
                <td>${p.dir_id}</td>
                <td>${p.salePrice}</td>
                <td>${p.supplier}</td>
                <td>${p.brand}</td>
                <td>${p.cutoff}</td>
                <td>${p.costPrice}</td>
                <td>
                    <a href="/show?cmd=input&id=${p.id}">编辑</a>
                    <a href="#" onclick="deleteBy(${p.id})">删除</a>
                </td>
            </tr>
        </c:forEach>
        <tr>
            <td colspan="9"><a href="/show?cmd=input" style="font-size: 32px">添加</a></td>
        </tr>
        <tr>
            <td colspan="9">
                <a href="#" onclick="goPage(1)">首页</a>
                <a href="#" name="prevPage" onclick="goPage(${pageResult.prevPage})">上一页</a>
                <a href="#" name="nextPage" onclick="goPage(${pageResult.nextPage})">下一页</a>
                <a href="#" onclick="goPage(${pageResult.totalPage})">尾页</a>
                当前页 ${pageResult.currentPage} / ${pageResult.totalPage} 页
                一共 ${pageResult.totalCount} 条数据
                跳转到[ <input type="number" step="1" onchange="changePage()" id="currentPage" name="currentPage"> ]
                每页[
                <select name="pageSize" onchange="changePage()">
                    <option value="3" ${pageResult.pageSize == 3?'selected':''}>3</option>
                    <option value="5" ${pageResult.pageSize == 5?'selected':''}>5</option>
                    <option value="10" ${pageResult.pageSize == 10?'selected':''}>10</option>
                </select>
                ]条数据
            </td>
        </tr>
    </table>
</form>
</body>
</html>
